package homework;





/*一 定义Worker类，包含String name，String job（岗位），int salary(工资）;
            a 属性私有，getset公开+全属性构造+toString
            b 增加方法

     */

    class Worker {
        private String name;    //姓名
        private String job;     //岗位
        private int salary;     //工资

        //    doJob方法
        public int doJob(int months) {
            System.out.println(this.name + "工作了" + months + "个月，获得" + this.salary * months + "工资");
            return this.salary * months;
        }
//    get set 公开

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }

        public String getJob() {
            return job;
        }

        public void setJob(String job) {
            this.job = job;
        }

        public int getSalary() {
            return salary;
        }

        public void setSalary(int salary) {
            this.salary = salary;
        }
        //全属性+toString

        public Worker(String name, String job, int salary) {
            this.name = name;
            this.job = job;
            this.salary = salary;
        }

        @Override
        public String toString() {
            return "Worker{" +
                    "name='" + name + '\'' +
                    ", job='" + job + '\'' +
                    ", salary=" + salary +
                    '}';
        }
    }

    /*
    二 定义SuperWorker类，派生于Worker类，增加 float bonus成员变量 奖金系数  ,范围在  【0,1】之间
    重写父类的doJob方法，  返回:总工资=普通工人总工资*(1+奖金系数)
    */
    class SuperWorker extends Worker {
        private float bonus;        //奖金系数

        public SuperWorker(String name, String job, int salary, float bonus) {
            super(name, job, salary);
            this.bonus = bonus;
        }

        public float getBonus() {
            return bonus;
        }

        public void setBonus(float bonus) {
            if (bonus >= 0 && bonus <= 1) {
                this.bonus = bonus;
            } else {
                System.out.println("bonus范围应该在【0,1】之间！");
            }
        }


        @Override
        public int doJob(int months) {
            return (int) (super.doJob(months) * ((1 + this.bonus)));
        }

        public int doJob(int months, int addtionalHours) {
            return (int) (super.doJob(months) + this.bonus * getSalary() * addtionalHours / 100);
        }
    }


    public class homework2 {
        public static void main(String[] args) {

            Worker w = new Worker("小A", "程序员", 10000);
            System.out.println(w.doJob(3));

            SuperWorker sw = new SuperWorker("小B", "经理", 10000, 0.2f);
            System.out.println(sw.doJob(3));
            System.out.println(sw.doJob(3, 200));
        }

    }


